$(function() {
	$("#email").on({
		'mouseover': function() {
			$(this).css("border-color", "red");
		},
		'blur': function() {

			if (!email($("#email").val())) {
				$(".ecuowu").css('display', 'block');
				$(".ezhengque").css('display', 'none');
			} else {
				$(".ezhengque").css('display', 'block');
				$(".ecuowu").css('display', 'none');
			}
		},
		'mouseout': function() {
			$(this).css("border-color", "#DDDDDD")
		}

	})
	$("#name").on({
		'mouseover': function() {
			$(this).css("border-color", "red");
		},
		'mouseout': function() {
			$(this).css("border-color", "#DDDDDD")
		}

	})
	$("#password").on({
		'mouseover': function() {
			$(this).css("border-color", "red");
		},
		'blur': function() {
			var password = $("#password").val()
			if (!pass(password)) {
				$(".mcuowu").css('display', 'block');
				$(".mzhengque").css('display', 'none');
			} else {
				$(".mzhengque").css('display', 'block');
				$(".mcuowu").css('display', 'none');
			}
		},
		'mouseout': function() {
			$(this).css("border-color", "#DDDDDD")
		}

	})
	$(".code").on({
		'click': function() {
			settime($(this))
			$.ajax({
				type: "get",
				url: "http://localhost:3000/users/sendEmail",
				async: true,
				data: {
					email: $("#email").val()
				},
				success: function(res) {
					console.log(res)
				}
			});
		},
		'mouseover': function() {
			$(".code").css("color", "red")
		},
		'mouseout': function() {
			$(".code").css("color", "#308eff")
		}
	})


	$(".zhuce").on({
		'click': function() {
			$.ajax({
				type: "post",
				url: "http://localhost:3000/users/register",
				async: true,
				data: {
					email: $("#email").val(),
					name: $("#name").val(),
					password: $("password").val(),
					name:$("#name").val(),
					password:$("#password").val(),
				},
				success: function(res) {
					console.log(res)
					alert(res.message)
					location.href = "../html/login.html"
				}
			});

		},

		'mouseover': function() {
			$(this).css("background", "green")
		},
		'mouseout': function() {
			$(this).css("background", "#308eff")
		}
	})


	/* 封装验证码获取倒计时函数 */
	var countdown = 59;
	function settime(obj) {
		obj.html(countdown+"秒后重新发送");
		countdown--;
		if (countdown == -2) {
			obj.html("获取验证码");
			countdown = 59;
			return;
		}
		setTimeout(function() {
			settime(obj)
		}, 1000);
	}
	
	//验证邮箱
	function email(email) {
		var reg =
		/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		return reg.test(email)

	}
	//密码验证
	
	function pass(password){
		var	reg=/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$).{3,}$/;
		return reg.test(password)
	}
	
})
